package com.itheima.admin.task;

import com.itheima.admin.service.WemediaNewsAutoScanService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @version 1.0
 * @description 说明
 * @package com.itheima.admin.task
 */
@Component
@Slf4j
public class SyncArticleTask {

    @Resource
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @XxlJob("syncArticleTask")
    public ReturnT<String> syncTask(String param){
        String uuid = UUID.randomUUID().toString();
        log.info("后台定时同步文章任务开始...{}", uuid);
        XxlJobLogger.log("后台定时同步文章任务开始...{}", uuid);
        // 业务流程
        try {
            wemediaNewsAutoScanService.syncArticles(param,uuid);
            log.info("后台定时同步文章任务完成...{}",uuid);
            XxlJobLogger.log("后台定时同步文章任务完成...{}",uuid);
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            log.error("同步文章数据失败!{}",uuid, e);
            XxlJobLogger.log("同步文章数据失败!{}",uuid,e);
            return ReturnT.FAIL;
        }
    }
}
